package com.wanmait.demo.controller.manageController;

import com.fasterxml.jackson.databind.json.JsonMapper;
import com.wanmait.demo.pojo.Admin;
import com.wanmait.demo.pojo.Role;
import com.wanmait.demo.service.AdminService;
import com.wanmait.demo.service.RoleService;
import com.wanmait.demo.util.Layui;
import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class AdminManageController {
    @Resource
    private  AdminService adminService;
    @Resource
    private RoleService roleService;
    @RequestMapping("adminManage")
    public String adminManage()
    {
        return "/manage/BackgroundManager";
    }

    @RequestMapping("getAdmin")
    @ResponseBody
    public Layui<Admin> getAdmin()
    {
        List<Admin> admins=adminService.findAll();
        Layui<Admin> adminLayui=Layui.successsWithData(0,admins);


        return adminLayui;
    }
    @RequestMapping("addAdmin")
    public ModelAndView addAdmin()
    {
        ModelAndView modelAndView=new ModelAndView();
        List<Role> roles=roleService.findAll();
        modelAndView.addObject(roles);
        modelAndView.setViewName("manage/addAdmin");
        return modelAndView;
    }
}
